package controllers

import (
	"fmt"
	"github.com/astaxie/beego"
)

type BaseController struct {
	beego.Controller
	isLogin string
}

func (this *BaseController) Prepare() {
	//userLogin := this.GetSession("userLogin")//session 判断是否已经登录
	userLogin := this.GetString("isLogin")
	fmt.Println(userLogin)
	if userLogin == "" {
		this.isLogin = "未登录"

		ret := output{200,2,"没有登录"} //output结构体在api控制器中已经定义
		this.Data["json"] = ret
		this.ServeJSON() //json输出
		this.StopRun() //终止运行
	} else {
		this.isLogin = "已登录"
	}
	this.Data["isLogin"] = userLogin
}

func (this *BaseController) Go404() {
	this.TplName = "404.tpl"
	return
}